package com.qyer.search.model.result;

import static com.qyer.search.model.result.SearchMetaInfo.EMPTY_SEARCH_META_INFO;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.qyer.commons.http.HttpResult;
import com.qyer.commons.http.InnerHttpResult;
import com.qyer.commons.http.NormalHttpResult;

import java.util.Collections;

/**
 * User: Z J Wu Date: 2016/02/26 Time: 15:44 Package: com.qyer.search.model.result
 */
public class MetaNormalHttpResult extends NormalHttpResult {

  public static HttpResult createEmptyMetaNormalResult(String serviceName, String namespace,
                                                       String requestId, long timeuse) {
    return new MetaNormalHttpResult(serviceName, namespace, timeuse,
                                    new InnerHttpResult(requestId, "asdf", Collections.emptyList()),
                                    EMPTY_SEARCH_META_INFO);
  }

  public static HttpResult createMetaNormalResult(String serviceName, String namespace,
                                                  String requestId, String strategy, long timeuse,
                                                  Object data, SearchMetaInfo metaInfo) {
    return (data == null) ? createEmptyNormalResult(serviceName, namespace, requestId, timeuse)
                          : new MetaNormalHttpResult(serviceName, namespace, timeuse,
                                                     new InnerHttpResult(requestId, strategy, data),
                                                     metaInfo);
  }

  @JsonProperty("meta_info")
  private SearchMetaInfo metaInfo;

  public MetaNormalHttpResult() {
  }

  public MetaNormalHttpResult(String serviceName, String namespace, long timeuse,
                              InnerHttpResult data, SearchMetaInfo metaInfo) {
    super(serviceName, namespace, timeuse, data);
    this.metaInfo = metaInfo;
  }

  public SearchMetaInfo getMetaInfo() {
    return metaInfo;
  }

  public void setMetaInfo(SearchMetaInfo metaInfo) {
    this.metaInfo = metaInfo;
  }
}
